import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      props: route => ({
        userId: route.query.userId
      }),
      component: () => import('../components/HomeScreen.vue')
    },
    {
      path: '/AppView/:id',
      name: 'AppView',
      props: route => ({
        id: route.params.id,
        userId: route.query.userId
      }),
      component: () => import('../views/AppView.vue')
    },
    {
      path: '/download/:userId',
      name: 'download',
      props: route => ({
        userId: route.params.userId
      }),
      component: () => import('../views/DownloadView.vue')
    },
    {
      path: '/user',
      name: 'user',

      component: () => import('../components/User.vue')
    },
    {
      path: '/sign',
      name: 'sign',
      component: () => import('../components/Sign.vue')
    },
    {
      path: '/toSearch',
      name: 'Search',
      props: route => ({
        userId: route.params.userId
      }),
      component: () => import('../views/Search.vue')
    },
    {
      path: '/RankingList',
      name: 'RankingList',
      props: route => ({
        userId: route.query.userId
      }),
      component: () => import('../views/RankingListView.vue')
    },
    {
      path: '/AppList',
      name: 'AppList',
      props: route => ({
        userId: route.query.userId
      }),
      component: () => import('../views/AppList.vue')
    },
    // 新增：匹配 /AppStore/apps 路径，接收 appType 查询参数
    {
      path: '/apps', // 路径固定为 /AppStore/apps
      name: 'apps',  // 路由名称（方便编程式导航）
      props: route => ({      // 通过 props 传递查询参数给组件
        appType: route.query.appType // 将查询参数 appType 传递给组件
      }),
      component: () => import('../components/HomeAppClassify.vue') // 关联组件
    }
  ],
})

export default router
